<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="me.yobol.greentable.commons.LoginStatus" %>
<%@ page import="me.yobol.greentable.commons.path.*" %>
<%@ page import="me.yobol.greentable.bean.DishesBean" %>
<%@ page import="me.yobol.greentable.bean.DishesCommentBean" %>
<%@ page import="me.yobol.greentable.service.UserService"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  	<head>
    
    <title>Dishes</title>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<style>
		#comment_list{
			border:1px;
			border-style:solid;
		}
	</style>
  	</head>
  
	<body>
	<%
		int loginStatus = (session.getAttribute("LoginStatus") == null) ? LoginStatus.ANONYMOUS : (Integer)session.getAttribute("LoginStatus");
		
		DishesBean dishes = (DishesBean)request.getSession().getAttribute("dishes");
		String dishesOwnerName = (String)request.getSession().getAttribute("dishesOwnerName");
		String dishesName = dishes.getDishesName();
		String dishesDescription = dishes.getDishesDescription();
		String dishesContent = dishes.getDishesContent();
		int dishesCommtentCtr = dishes.getDishesCommentCtr();
		int dishesFavouriteCtr = dishes.getDishesFavouriteCtr();
		int dishesScansCtr = dishes.getDishesScansCtr();
		
		List<DishesCommentBean> comments = (List<DishesCommentBean>)request.getSession().getAttribute("dishesComments");
		int userId = (session.getAttribute("uId") == null) ? 0 : (Integer)session.getAttribute("uId");
		
	%>
		<h1><%=dishesName %></h1>
		<p><span style="color:#ccc;"><%=dishesDescription %></span> 作者:<%=dishesOwnerName %></p>
		<p>浏览数:<%=dishesScansCtr %>&nbsp;收藏数:<%=dishesFavouriteCtr %>&nbsp;评论:<%=dishesCommtentCtr %></p>
		<div><%=dishesContent %></div>
		
		<!-- 评论 -->
		<div>
			<form action="<%=SPath.sCreateDishesComment(request) %>" method="post" onsubmit="return checkpost();">
			<%
				if(loginStatus == LoginStatus.ANONYMOUS){
			%>
				<p>你还没登录！请<a href="<%=PPath.pLogin(request) %>">登录</a>后评论。</p>
			<%
				}else{
			%>
				<textarea rows="10" cols="30" id="comment_content" name="commentContent" ></textarea>
				<input type="hidden" name="dishesId" value="<%=dishes.getDishesId() %>"/>
				<input type="submit" value="发表评论"/>
			<%
				}
			%>
			</form>
			<div>
				<%
					if(!comments.isEmpty()){
						for(DishesCommentBean c : comments){
				%>
						<div id="comment_list">
							<p>
							<%=UserService.getUNameByUID(c.getUserId()) %>
							<%
								if(c.getUserId() == userId){
							%>
									&nbsp;&nbsp;<a href="<%=SPath.sDeleteDishesComment(request,"?dishesCommentId=" + c.getDishesCommentId() + "&dishesId=" + dishes.getDishesId()) %>">删除</a>
							<%
								}
							%>
							</p>
							<p><%=c.getDishesCommentContent() %></p>
						</div>
				<%
						}
					}
				%>
			</div>
		</div>
		
		<script type="text/javascript" src="<%=JPath.jJquery(request)%>"></script>
		<script type="text/javascript" src="<%=JPath.jComment(request) %>" charset="gb2312"></script>
  	</body>
</html>
